package edu.gdin.ecommerce.model;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import edu.gdin.ecommerce.util.DicConverter;

/**
 * AccountRecord entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "t_account_record", catalog = "ecommerce")
public class AccountRecord implements java.io.Serializable {

	// Fields

	/**
	 * 
	 */
	private static final long serialVersionUID = 1615071590745273182L;
	private Integer accountRecordId;
	private String operater;
	private Date time;
	private Integer operateType;
//	private Integer accountId;
	private String cardNo;
	private String attachNo;
	private Double operateAmount;
	private Double leftAmount;
	private String recordDesc;
	
	private Account account;

	// Constructors

	/** default constructor */
	public AccountRecord() {
	}

	/** full constructor */
	public AccountRecord(Integer accountRecordId, String operater, Date time,
			Integer operateType, String cardNo, String attachNo,
			Double operateAmount, Double leftAmount, String recordDesc,
			Account account) {
		super();
		this.accountRecordId = accountRecordId;
		this.operater = operater;
		this.time = time;
		this.operateType = operateType;
		this.cardNo = cardNo;
		this.attachNo = attachNo;
		this.operateAmount = operateAmount;
		this.leftAmount = leftAmount;
		this.recordDesc = recordDesc;
		this.account = account;
	}

	// Property accessors
	@Id
	@GeneratedValue
	@Column(name = "ACCOUNT_RECORD_ID", unique = true, nullable = false)
	public Integer getAccountRecordId() {
		return this.accountRecordId;
	}

	public void setAccountRecordId(Integer accountRecordId) {
		this.accountRecordId = accountRecordId;
	}

	@Column(name = "OPERATER", nullable = false, length = 20)
	public String getOperater() {
		return this.operater;
	}

	public void setOperater(String operater) {
		this.operater = operater;
	}

	@Column(name = "TIME", nullable = false, length = 19)
	public Date getTime() {
		return this.time;
	}

	public void setTime(Date time) {
		this.time = time;
	}

	@Column(name = "OPERATE_TYPE", nullable = false)
	public Integer getOperateType() {
		return this.operateType;
	}

	public void setOperateType(Integer operateType) {
		this.operateType = operateType;
	}

	@Column(name = "CARD_NO", nullable = false, length = 20)
	public String getCardNo() {
		return this.cardNo;
	}

	public void setCardNo(String cardNo) {
		this.cardNo = cardNo;
	}

	@Column(name = "ATTACH_NO", length = 30)
	public String getAttachNo() {
		return this.attachNo;
	}

	public void setAttachNo(String attachNo) {
		this.attachNo = attachNo;
	}

	@Column(name = "OPERATE_AMOUNT", nullable = false, precision = 12)
	public Double getOperateAmount() {
		return this.operateAmount;
	}

	public void setOperateAmount(Double operateAmount) {
		this.operateAmount = operateAmount;
	}

	@Column(name = "LEFT_AMOUNT", nullable = false, precision = 12)
	public Double getLeftAmount() {
		return this.leftAmount;
	}

	public void setLeftAmount(Double leftAmount) {
		this.leftAmount = leftAmount;
	}

	@Column(name = "RECORD_DESC", length = 200)
	public String getRecordDesc() {
		return this.recordDesc;
	}

	public void setRecordDesc(String recordDesc) {
		this.recordDesc = recordDesc;
	}
	
	
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "ACCOUNT_ID", nullable = false)
	public Account getAccount() {
		return account;
	}

	public void setAccount(Account account) {
		this.account = account;
	}
	
	public String operateTimeToString(){
		SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
		if(time!=null)
			return fmt.format(time);
		return null;
	}
	
	public String operateTypeToStirng(){
		return DicConverter.dicMapConvert("DIC_ACCOUNT_OPER_TYPE", operateType);
	}

}